package com.abe.jmcl.android.share;

import android.content.ContentResolver;
import android.content.Intent;
import android.content.res.Resources;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.DrawableRes;

import com.abe.jmcl.R;
import com.abe.jmcl.utils.NormalUtils;
import com.abeframe.core.ConstantCore;
import com.abeframe.core.base.MVPBaseActivity;
import com.abeframe.core.base.MVPBasePresenter;

import java.io.File;

import butterknife.OnClick;

public class AndShareActivity extends MVPBaseActivity {
    @Override
    protected MVPBasePresenter createPresenter() {
        return null;
    }

    @Override
    protected int getThemeResId() {
        return 0;
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_share_and;
    }

    @Override
    protected void init(Bundle savedInstanceState) {

    }

    @Override
    protected void initDatas() {

    }

    @OnClick(R.id.item_share_txt)
    public void onSTClicked() {
        Intent textIntent = new Intent(Intent.ACTION_SEND);
        textIntent.setType("text/plain");
        textIntent.putExtra(Intent.EXTRA_TEXT, "这是一段分享的文字");
        startActivity(Intent.createChooser(textIntent, "分享"));
    }

    @OnClick(R.id.item_share_img)
    public void onSIClicked() {
        String path = getResourcesUri(R.drawable.icon_app);
        Intent imageIntent = new Intent(Intent.ACTION_SEND);
        imageIntent.setType("image/jpeg");
        imageIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(path));
        startActivity(Intent.createChooser(imageIntent, "分享"));
    }

    @OnClick(R.id.item_share_file)
    public void onSFClicked() {
        String path = ConstantCore.FILE_ROOT_PATH + File.separator + "commonTemplate.pdf";
        Uri uri = Uri.fromFile(new File(path));
        Intent imageIntent = new Intent(Intent.ACTION_SEND);
        imageIntent.setType("application/pdf");
        imageIntent.putExtra(Intent.EXTRA_STREAM, uri);
        startActivity(Intent.createChooser(imageIntent, "分享"));
    }

    private String getResourcesUri(@DrawableRes int id) {
        Resources resources = getResources();
        String uriPath = ContentResolver.SCHEME_ANDROID_RESOURCE + "://" +
                resources.getResourcePackageName(id) + "/" +
                resources.getResourceTypeName(id) + "/" +
                resources.getResourceEntryName(id);
        NormalUtils.w("Uri:" + uriPath);
        return uriPath;
    }
}
